﻿Imports System.Reflection

<ComClass(ClsAcadEntity.ClassId, ClsAcadEntity.InterfaceId, ClsAcadEntity.EventsId)>
Public Class ClsAcadEntity
#Region "COM GUID"
    ' 这些 GUID 提供此类的 COM 标识 
    ' 及其 COM 接口。若更改它们，则现有的
    ' 客户端将不再能访问此类。
    Public Const ClassId As String = "c970febc-3cf9-40c0-bcf6-12170647785a"
    Public Const InterfaceId As String = "92684477-7744-401e-98d3-ecebc23353cf"
    Public Const EventsId As String = "5805492f-dd34-49d3-9201-29aa53bce434"
#End Region

    ' 可创建的 COM 类必须具有一个不带参数的 Public Sub New() 
    ' 否则， 将不会在 
    ' COM 注册表中注册此类，且无法通过
    ' CreateObject 创建此类。
    Public Sub New()
        MyBase.New()
    End Sub

    Private _ObjectName As String
    Public Property ObjectName() As String
        Get
            Return _ObjectName
        End Get
        Set(ByVal value As String)
            _ObjectName = value
        End Set
    End Property
    Public ReadOnly Property ClassName() As String
        Get
            Return TypeName(Me.AcadObject)
        End Get
    End Property


    Private _ObjectID As Long
    Public Property ObjectID() As Long
        Get
            Return _ObjectID
        End Get
        Set(ByVal value As Long)
            _ObjectID = value
        End Set
    End Property

    Private _OwnerID As Long
    Public Property OwnerID() As Long
        Get
            Return _OwnerID
        End Get
        Set(ByVal value As Long)
            _OwnerID = value
        End Set
    End Property

    Private _Handle As String
    Public Property Handle() As String
        Get
            Return _Handle
        End Get
        Set(ByVal value As String)
            _Handle = value
        End Set
    End Property

    Private _layer As String
    Public Property Layer() As String
        Get
            Return _layer
        End Get
        Set(ByVal value As String)
            _layer = value
        End Set
    End Property

    Private _Linetype As String
    Public Property Linetype() As String
        Get
            Return _Linetype
        End Get
        Set(ByVal value As String)
            _Linetype = value
        End Set
    End Property

    Private _LinetypeScale As Double
    Public Property LinetypeScale() As Double
        Get
            Return _LinetypeScale
        End Get
        Set(ByVal value As Double)
            _LinetypeScale = value
        End Set
    End Property


    Private _Lineweight As acLineWeight
    Public Property Lineweight() As acLineWeight
        Get
            Return _Lineweight
        End Get
        Set(ByVal value As acLineWeight)
            _Lineweight = value
        End Set
    End Property

    Public AcadObject As Object

    Public Sub CteateFromCad(acObj As Object)

        Me.AcadObject = acObj
        Dim t = Me.GetType()
        For Each item As PropertyInfo In t.GetProperties().ToList().Where(Function(c) c.CanWrite).ToList()
            Dim val = CallByName(acObj, item.Name, CallType.Get, Nothing)
            If val IsNot Nothing Then
                If val.GetType().IsCOMObject Then
                    item.SetValue(Me, val.ColorIndex, Nothing)
                Else
                    item.SetValue(Me, val, Nothing)
                End If
            End If
        Next
    End Sub

    Enum acLineWeight
        acLnWtByLayer = -1
        acLnWtByBlock = -2
        acLnWtByLwDefault = -3
        acLnWt000 = 0
        acLnWt005 = 5
        acLnWt009 = 9
        acLnWt013 = 13
        acLnWt015 = 15
        acLnWt018 = 18
        acLnWt020 = 20
        acLnWt025 = 25
        acLnWt030 = 30
        acLnWt035 = 35
        acLnWt040 = 40
        acLnWt050 = 50
        acLnWt053 = 53
        acLnWt060 = 60
        acLnWt070 = 70
        acLnWt080 = 80
        acLnWt090 = 90
        acLnWt100 = 100
        acLnWt106 = 106
        acLnWt120 = 120
        acLnWt140 = 140
        acLnWt158 = 158
        acLnWt200 = 200
        acLnWt211 = 211

    End Enum
End Class

